package com.thread.demo11;

import java.text.SimpleDateFormat;
import java.util.Date;

public class WaitDemo3 {
	
	static class Thread2 extends Thread{
		private Thread a;
	    public Thread2(Thread a) {
	        this.a = a;
	    }
		@Override
		public void run() {
			synchronized (a) {
	            System.out.println("B begin " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
	            try {
	            	System.out.println("a是否活着："+a.isAlive());
	            a.wait();
	            } catch (InterruptedException e) {
	                e.printStackTrace();
	            }
	            System.out.println("B end " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
	        }
	    }
	}
	
	static class Thread1 extends Thread{
		@Override
		public void run() {
			synchronized (this) {
	            System.out.println("A begin " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
	            try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
				}
	            System.out.println("A end " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
	        }
		}
		
	}
	
	public static void main(String[] args) throws InterruptedException {
		Thread1 thread = new Thread1();
        Thread2 thread2 = new Thread2(thread);
        thread2.start();
        Thread.sleep(100);
        thread.start();
        
        Thread.sleep(100);
        System.out.println("main end "+new SimpleDateFormat("HH:mm:ss").format(new Date()));
	}

}
